import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-03-16
 * Time: 16:43
 */
@WebServlet("/GetParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //预测浏览器会发一个形如/getParameter?studentId=10&classId=20请求
        //借助req里的getParameter方法就拿到query string中的键值对内容
        //getParameter得到的是String类型的结果
        String studentId = req.getParameter("studentId");
        String classId = req.getParameter("classId");
//        resp.setContentType("text/html");
        resp.setContentType("text/html; charset=utf8");
//        resp.setCharacterEncoding("utf8");
//        resp.getWriter().write("studentId = " + studentId + " classId = " + classId );
        resp.getWriter().write("学生id = " + studentId + " 班级id = " + classId);
    }
}
